<?php 
if($this->session->userdata('role') != null){
	if($this->session->userdata('role') == 1){
include 'include/header.php';
?>
<style>

</style>
<script>
function modal_preview_proposal(e){
				e.preventDefault();
				$('#ajaxModal').remove();
				var url = $(e.target).attr('href');
				$('<div class="modal" id="ajaxModal"><div class="modal-body"></div></div>').appendTo('body');
				 $('#ajaxModal').modal();
				 $('#ajaxModal').load(url);
				//console.log(url.toString());
}

function modal_share_link(e){
	e.preventDefault();
	$('#ajaxModal2').remove();
	var url = $(e.target).attr('href');
	$('<div class="modal" id="ajaxModal2"><div class="modal-body"></div></div>').appendTo('body');
	$('#ajaxModal2').modal();
	$('#ajaxModal2').load(url);
}

function modal_preview_data(e){
				e.preventDefault();
				$('#ajaxModal').remove();
				var url = $(e.target).attr('href');
				$('<div class="modal" id="ajaxModal"><div class="modal-body"></div></div>').appendTo('body');
				 $('#ajaxModal').modal();
				 $('#ajaxModal').load(url);
				//console.log(url.toString());
}
</script>
<?php
if($this->session->userdata('username') == null){} else{
?>
<div class="form-group">
<form action="<?php echo base_url().'index.php/kuesioner/'; ?>">
<button class="btn btn-primary">Create Kuesioner</button>
</form>
</div>
<?php
}
?>

<?php 
if(!$kuesioner){
 echo 'Belum ada data';
} else{
if(count($kuesioner) <= 6){
	$d = 0;
} else
	{
		$d = floor(count($kuesioner)/6);
	}

$b = count($kuesioner)%6;
//var_dump($d);
//var_dump($b);
	
$indeks_data = 0;

for($c = 0; $c < $d; $c++){
?>
<div class="form-group">
<div class="row">
<?php

$a = 1;
for($e = 0; $e < 6; $e++){
?>
  <div class="col-sm-6 col-md-2">
    <div class="thumbnail">
      <div class="caption" style="word-wrap: break-word;max-width: 189px;">
		<img src="<?php echo base_url().'word.jpg'; ?>" alt="..." height="60" width="60">
        <h4 style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['nama_kuesioner']; ?></h4>
        <p style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['deskripsi']; ?></p>        
        <p style=""><?php echo ($kuesioner[$indeks_data]['reliabilitas'] == 1)? "Reliabel" : " Tidak Reliabel" ?></p>        
        <p style=""><?php echo ($kuesioner[$indeks_data]['validitas'] == 1)? "Valid" : " Tidak Valid" ?></p>        
		<div style="margin-left:0px; height: 40px; margin-top: -5px;" class="row" hidden>
		<button onclick="delete_penelitian(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>, event)" class="btn btn-danger" title="Hapus Penelitian">X</button>
		<?php
		if($this->session->userdata('username'))
		{
		?>
		<a href="#"><img src="<?php echo base_url().'assets/img/share.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/share_link/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_share_link(event)" title="share link kuesioner!"></img></a>
		<a  href="<?php echo base_url().'index.php/kuesioner/edit_kuesioner/'.$kuesioner[$indeks_data]['id_kuesioner'];?>"><img src="<?php echo base_url().'assets/img/edit.png'; ?>" width="20px" title="edit kuesioner!"></img></a>
		<a  href="<?php echo base_url().'index.php/kuesioner/cetak_kuesioner/'.$kuesioner[$indeks_data]['id_kuesioner'];?>"><img src="<?php echo base_url().'assets/img/edit.png'; ?>" width="20px" title="cetak kuesioner!"></img></a>
		<?php
		} else {
		?>
			<a  href="#" ><img src="<?php echo base_url().'assets/img/preview_data.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_data_responden/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_preview_data(event)" title="lihat data"></img></a>
		<?php
		}
		
		if($kuesioner[$indeks_data]['file_proposal'] != null){
		?>
		<a  href="#"><img src="<?php echo base_url().'assets/img/preview.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_proposal/'.$kuesioner[$indeks_data]['file_proposal']?>" onclick="modal_preview_proposal(event)" title="preview metodologi"></img></a>
		<?php
		}
		?>
		<button onclick="delete_penelitian(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>, event)" class="btn btn-danger" title="Hapus Penelitian" style="margin-left: 151px; margin-top: -46px;">X</button>
	  </div>
      </div>
    </div>
  </div>
<?php 
$indeks_data++;
}
?>
</div> 
</div>
<?php
}

?>
<div class="form-group">
	<div class="row">
	<?php
		for($e = 0; $e < $b; $e++){
	?>
	<div class="col-sm-6 col-md-2">
    <div class="thumbnail">
      <div class="caption" style="word-wrap: break-word;max-width: 189px;">
		<img src="<?php echo base_url().'excel.jpg'; ?>" alt="..." height="60" width="60">
        <h4 style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['nama_kuesioner']; ?></h4>
        <p style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"><?php echo $kuesioner[$indeks_data]['deskripsi']; ?></p>
		<p style=""><?php echo ($kuesioner[$indeks_data]['reliabilitas'] == 1)? "Reliabel" : " Tidak Reliabel" ?></p>        
        <p style=""><?php echo ($kuesioner[$indeks_data]['validitas'] == 1)? "Valid" : " Tidak Valid" ?></p>
		<div style="margin-left:0px; height: 40px; margin-top: -5px;" class="row" hidden>
		<?php
		if($this->session->userdata('username'))
		{
		?>
		<a href="#"><img src="<?php echo base_url().'assets/img/share.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/share_link/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_share_link(event)" title="share link kuesioner!"></img></a>
		<a  href="<?php echo base_url().'index.php/kuesioner/edit_kuesioner/'.$kuesioner[$indeks_data]['id_kuesioner'];?>"><img src="<?php echo base_url().'assets/img/edit.png'; ?>" width="20px" title="edit kuesioner!"></img></a>
		<a  href="<?php echo base_url().'index.php/kuesioner/cetak_kuesioner/'.$kuesioner[$indeks_data]['id_kuesioner'];?>"><img src="<?php echo base_url().'assets/img/print.png'; ?>" width="20px" title="cetak kuesioner!"></img></a>
		<?php
		} else{
		?>
			<a  href="#" ><img src="<?php echo base_url().'assets/img/preview_data.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_data_responden/'.$kuesioner[$indeks_data]['id_kuesioner'];?>" onclick="modal_preview_data(event)" title="lihat data"></img></a>
		<?php
		}
		
		if($kuesioner[$indeks_data]['file_proposal'] != null){
		?>
		<a  href="#"><img src="<?php echo base_url().'assets/img/preview.png'; ?>" width="20px" href="<?php echo base_url().'index.php/kuesioner/lihat_proposal/'.$kuesioner[$indeks_data]['file_proposal']?>" onclick="modal_preview_proposal(event)" title="preview metodologi"></img></a>
		<?php
		}
		?>
		<button onclick="delete_penelitian(<?php echo $kuesioner[$indeks_data]['id_kuesioner'];?>, event)" class="btn btn-danger" title="Hapus Penelitian" style="margin-left: 151px; margin-top: -46px;">X</button>
	  </div>
      </div>
    </div>
  </div>
	<?php
	$indeks_data++;
		}
	}
	?>
	</div>
</div>
<?php
include 'include/footer.php';
} else{ 
		echo 'Anda belum login, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">kembali</a>';
	}
} else
	{
		echo 'Anda belum login, silahkan login terlebih dahulu dengan klik link berikut';
		echo '<a href="'.base_url('index.php/guest').'">kembali</a>';
	}
	
?>
<script>
$(document).ready(function(){

	$(".thumbnail").hover(function() {
			$(this).children('.caption').children('.row').css('display', 'block');
			$(this).children('.caption').children('h4').css('text-overflow','');
			$(this).children('.caption').children('h4').css('overflow','');
			$(this).children('.caption').children('h4').css('white-space','');
			$(this).children('.caption').children('p').css('text-overflow','');
			$(this).children('.caption').children('p').css('overflow','');
			$(this).children('.caption').children('p').css('white-space','');
		  }, function() {
			$(this).children('.caption').children('.row').css('display', 'none');
			$(this).children('.caption').children('h4').css('text-overflow','ellipsis');
			$(this).children('.caption').children('h4').css('overflow','hidden');
			$(this).children('.caption').children('h4').css('white-space','nowrap');
			$(this).children('.caption').children('p').css('text-overflow','ellipsis');
			$(this).children('.caption').children('p').css('overflow','hidden');
			$(this).children('.caption').children('p').css('white-space','nowrap');
			});
		 
		

})

function delete_penelitian(id_kuesioner,e)
	{
	
	var x = confirm('Anda yakin akan menghapus data ini?');
	if(x){
		$.post('<?php echo base_url(); ?>index.php/kuesioner/hapus_penelitian/'+id_kuesioner, {
			});
		} else{e.preventDefault();}
	
	}

</script>